// pages/Index/RechargeList/RechargeList.js
const controller=require("../../controllers/Controller").controller
const controllers=require("../../controllers/controllerIndex").controller
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  //获取店铺首页信息
  getShopMsg(){
    let that=this
    controllers.shopInfo({
      sessionId: wx.getStorageSync('token'),
      shopId:wx.getStorageSync('shopId')
    }).then(res =>{
      
      let newTime=new Date().getTime();
      let lastDay=0;
      if(res.data.endTime){
       
      let endTime=new Date(res.data.endTime.replace(/-/g,"/")).getTime();
      lastDay=Math.ceil((endTime-newTime)/1000/24/3600);
      
     
      that.setData({
        lastDay 
      })
      console.log(lastDay)
      wx.setStorageSync('endTime', res.data.endTime)
      wx.setStorageSync('shopGroupEndTime', res.data.shopGroupEndTime)
      }
      that.setData({
        storeInfo : res.data,
       
      })
      wx.setStorageSync('typeId', res.data.typeId)
      if(res.data.shopGroupEndTime){
        let shopGroupEndTime=res.data.shopGroupEndTime.replace(/-/g, "/")
        if (shopGroupEndTime) {
          if (new Date(shopGroupEndTime).getTime() > newTime) {
            this.setData({
              Effective: true
            })
            wx.setStorageSync('Effective', true)
          } else {
            this.setData({
              Effective: false
            })
            wx.setStorageSync('Effective', false)
          }
        }
      }else {
        this.setData({
          Effective: false
        })
        wx.setStorageSync('Effective', false)
      }
    })
   },
  //跳转其他充值页
  toOtherPage(e){
    let index=e.currentTarget.dataset.index
    if(index===0){
      wx.navigateTo({
        url: '/pages/Index/bill/bill?type=0',
      })
    }else if(index===1){
      wx.navigateTo({
        url: '/pages/Index/bill/bill?type=1',
      })
    }else if(index===2){
      wx.navigateTo({
        url: '/pages/Index/shopCustomization/shopCustomization',
      })
    }else if(index===3){
      wx.navigateTo({
        url: '/pages/Index/DesignPosters/DesignPosters',
      })
    }else if(index===4){
      wx.navigateTo({
        url: '/pages/Index/openService/openService?no=11',
      })
    }else if(index===5){
      wx.navigateTo({
        url: '/pages/Index/openService/openService?no=13',
      })
    }else if(index===6){
      wx.navigateTo({
        url: '/pages/Index/openService/openService?no=12',
      })
    }else{
      wx.showToast({
        icon:"none",
        title: '暂未开放',
        duration:1500
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      shopId: wx.getStorageSync('shopId'),
      endTime: wx.getStorageSync('endTime').slice(0,10)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getShopMsg()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})